package com.blueocean_health.care.management.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.blueocean_health.care.management.common.base.string.StringUtils;
import com.blueocean_health.care.management.domain.base.SysResult;
import com.blueocean_health.care.management.service.UploadService;

/**
* @author huyanqiu
* @date 2018年6月26日 下午3:53:03
* @version 版本号：1.0
*/
@RestController
@RequestMapping("/upload")
public class UploadController {

	@Autowired
	private UploadService uploadService;
	
	/**
	 * 上传图片
	 * @throws Exception 
	 */
	@RequestMapping(value="/img")
	public SysResult upload(@RequestParam(value="img") MultipartFile imgFile,HttpServletRequest request) throws Exception {
		String pictype = "";
		String header = request.getHeader("pictype");
		String parameter = request.getParameter("pictype");
		if (!StringUtils.isEmpty(header)) {
			pictype = header;
		} else if (!StringUtils.isEmpty(parameter)) {
			pictype = parameter;
		} else {
			return SysResult.error("请标识图片类型");
		}
		SysResult upload = uploadService.upload(imgFile, pictype);
		if (null != upload) {
			return upload;
		} else {
			return SysResult.error("上传失败");
		}
	}
	
}
